package com.teamone.etl.datasource.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.teamone.etl.datasource.entity.DataSource;
import com.teamone.etl.datasource.service.DataSourceFeignService;
import com.teamone.etl.datasource.service.DataSourceService;
import com.teamone.etl.exception.CustomException;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 @author WangZhuoRan */
@RestController
public class DataSourceFeignController extends ApiController {

    @Resource
    private DataSourceFeignService dataSourceFeignService;

    @Resource
    private DataSourceService dataSourceService;

    @GetMapping("/getAllDataSource")
    public List<DataSource> getAllDataSource (){
        return dataSourceService.getAllNotDisabledAndClearSensitiveInformation();
    }

    @GetMapping("/getAllDataBaseByDataSourceId/{dataSourceId}")
    public List<String> getAllDataBaseByDataSourceId (@PathVariable("dataSourceId") Integer id) throws CustomException {
        return dataSourceFeignService.getAllDataBaseByDataSourceId(id);
    }

    @GetMapping("/getAllTableByDataBaseName/{dataSourceId}")
    public List<String> getAllTableByDataBaseName (@PathVariable("dataSourceId") Integer id,
                                                   @RequestParam("dataBaseName") String dataBaseName) throws CustomException {
        return dataSourceFeignService.getAllTableByDataBaseName(id,dataBaseName);
    }

    @GetMapping("/getAllColumnByTableName/{dataSourceId}")
    public Map<String, List<String>> getAllColumnByTableName (@PathVariable("dataSourceId") Integer id,
                                                              @RequestParam("tableName") String tableName,
                                                              @RequestParam("dataBaseName") String dataBaseName) throws CustomException {
        return dataSourceFeignService.getAllColumnByTableName(id,tableName,dataBaseName);
    }

}
